////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008 Duykham.
// All Rights Reserved.
// Author: Duykham (duykham@gmail.com)
// Modified: 20081030
// TODO: 
//
////////////////////////////////////////////////////////////////////////////////
package dk.agrasys
{
	import mx.collections.ArrayCollection;
		
	[Bindable]
	/**
	 * All informations about sensors 
	 * @author Duykham
	 * 
	 */
	public class Sensor
	{
		public var id:String;
		public var name:String;
		public var nhietdo:String;
		public var doam:String;
		public var time:String;
		public var xPos:int;
		public var yPos:int;
		public var tracks:ArrayCollection;
		public var selected:int;

		private var track:Track;
		
		/**
		 * Constructor 
		 * @param sensor
		 * 
		 */		
		public function Sensor(sensor:Object=null)
		{
			tracks = new ArrayCollection();
			if (sensor != null)
			{
				fill(sensor);
			}
		}
		
		/**
		 * Load informations from XML node to an array element 
		 * @param sensor
		 * 
		 */		
		public function fill(sensor:Object):void
		{
			/*this.name = sensor.id;
			this.description = sensor.description;*/
			this.id = sensor.id;
			this.name = sensor.name;
			/* if(sensor.n == null) 
			{
				this.nhietdo = "00.0";
			}
			else
			{ */
				this.nhietdo = sensor.n;
			//};
			/* if(sensor.d == null) 
			{
				this.doam = "00.0";
			}
			else
			{ */
				this.doam = sensor.d;
			//};
			if (sensor.ti == null)
			{
				this.time = "...";
			}
			else
			{
				this.time = sensor.ti;
			}
			this.xPos = sensor.x;
			this.yPos = sensor.y;
			this.selected = 0;
			
			if(sensor.t!=null)
			{
				trace(sensor.t);
				for (var i:int=0; i < sensor.t.length; i++)
				{
					track = new Track(sensor.t[i]);
					tracks.addItem(track);
				}
			}
			else
			{
				for (var j:int=0; j < 120; j++)
				{
					track = new Track();
					tracks.addItem(track);
				}
			}
		}
	}
}